using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// 控制测试面板的启动运行
/// 获取当前关节运动顺序和关节旋转度数
/// </summary>
public class Running_TestPanel_Renew : MonoBehaviour
{
    public float[,] runningSequenceImfor; // 储存运行顺序和旋转值

    // 运行顺序计数
    public int i_sequence_front = 0; 

    public static bool start_ReadImfor = false; // 开始读取数据，true为读完，false为未读完（即开始读取）

    MA_ReadAngels mA_ReadAngles;

    Running_TestPanel running_TestPanel;

    MA_Joint1Contol mA_Joint1Contol;



    private void Awake()
    {
        runningSequenceImfor = new float[20,2];
    }
    // Start is called before the first frame update
    void Start()
    {
        //mA_ReadAngles = new MA_ReadAngels();
        mA_Joint1Contol = new MA_Joint1Contol();
        running_TestPanel = new Running_TestPanel();
        
        // 初始化StartReadImfor状态为false
        start_ReadImfor = false;
    }

    // Update is called once per frame
    void Update()
    {

    }

    /// <summary>
    /// 查找关节编号
    /// </summary>
    /// <param name="runningJointModularObject"></param>
    /// <returns></returns>
    private float ReadJointModularObject(string runningJointModularObject)
    {
        if (runningJointModularObject == "Object_Green_Joint1(Clone)")
            return 1;
        else if (runningJointModularObject == "Object_Green_Joint2(Clone)")
            return 2;
        else if (runningJointModularObject == "Object_Green_Joint3(Clone)")
            return 3;
        else if (runningJointModularObject == "Object_Green_Joint4(Clone)")
            return 4;
        else
            return 5;
    }

    /// <summary>
    /// 获取关节旋转顺序和对应的旋转度数
    /// 并将对应的信息传给关节组件
    /// </summary>
    public void GetImfor()
    {
        // 按下开始按钮，读取与运动开始进行的标志，此处为初始化
        start_ReadImfor = false;

        for (i_sequence_front = 0; i_sequence_front < 20; i_sequence_front++)                                 
        {
            // 若发现未赋值的object，跳出循环
            if(FindObjectOfType<GetImfor_PutJointModularObject>().JointObjectList[i_sequence_front] != null)
            {
                // 获取需要进行运动的关节
                runningSequenceImfor[i_sequence_front,0] = ReadJointModularObject(FindObjectOfType<GetImfor_PutJointModularObject>().JointObjectList[i_sequence_front].name);
                // 获取此关节的旋转度数
                runningSequenceImfor[i_sequence_front,1] = FindObjectOfType<GetImfor_PutJointModularObject>().angleInput[i_sequence_front];       
            }   

            else
            {
                Debug.Log(123);
                // 发送读取与运动开始是否进行的信息，此处为开始信息
                start_ReadImfor = true;

                // 发出信号后，退出循环
                return;
            }                                                                                                                                                                                                                                     
        }
    }
    


    
/*
    /// <summary>
    /// 修改对应编号的关节状态为false
    /// </summary>
    /// <param name="_num"></param>
    private void Change_ToFalse_mA_RotateFinish(int _num)
    {
        if (_num == 1)
            MA_ReadAngels.mA_RotateFinish_1 = false;
        else if (_num == 2)
            MA_ReadAngels.mA_RotateFinish_2 = false;
        else
            MA_ReadAngels.mA_RotateFinish_3 = false;
    }

    /// <summary>
    /// 修改对应编号的关节状态为true
    /// </summary>
    /// <param name="_num"></param>
    private void Change_ToTrue_mA_RotateFinish(int _num)
    {
        if (_num == 1)
            MA_ReadAngels.mA_RotateFinish_1 = true;
        else if (_num == 2)
            MA_ReadAngels.mA_RotateFinish_2 = true;
        else
            MA_ReadAngels.mA_RotateFinish_3 = true;
    }
    */
}
